package com.yonyou.crm.sys.menu.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yonyou.crm.common.biz.service.BaseBizServiceImpl;
import com.yonyou.crm.common.model.util.ModelUtil;
import com.yonyou.crm.sys.menu.entity.MenuGroupVO;
import com.yonyou.crm.sys.menu.entity.MenuVO;
import com.yonyou.crm.sys.menu.entity.MenuGroupDO;

@Service
public class MenuGroupServiceImpl extends BaseBizServiceImpl<MenuGroupDO>{

	@Autowired
	private MenuBizServiceImpl menuService;
	/**
	 * 获取菜单分组
	 * @param moduleid
	 * @return
	 */
	public List<MenuGroupVO> getPcMenuGroup(Long moduleId){
		
		List<MenuGroupDO> menuGroups = dao.selectVoList(MenuGroupDO.class, "getMenuGroupList", moduleId);
		
		if(menuGroups!=null&&menuGroups.size()>0){
			List<MenuGroupVO> menuGroupVos = new ArrayList<MenuGroupVO>(menuGroups.size()); 
			for(MenuGroupDO menuGroupDo : menuGroups){
				MenuGroupVO vo = ModelUtil.copyModel(menuGroupDo, MenuGroupVO.class);
				List<MenuVO>  menuVos= menuService.getMenuList(vo.getId());
				if(menuVos!=null && menuVos.size() > 0){
					vo.setChild(menuVos.toArray(new MenuVO[menuVos.size()]));
					menuGroupVos.add(vo);
				}
			}
			return menuGroupVos;
		}
		return null;
	}
	
	
	
}
